﻿
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="LAY-topic-list" lay-filter="LAY-topic-list"></table>
        </div>
    </div>
</div>

<script type="text/html" id="publishedTpl">
    <input type="checkbox" name="Installed" lay-skin="switch" value="{{d.SystemName}}" lay-filter="published" lay-text="安装|卸载" {{ d.Installed ? 'checked' : ''}}>
    &nbsp;&nbsp;
</script>
<script type="text/html" id="isEnabledTpl">
    {{#  if(d.CanChangeEnabled){ }}
    <input type="checkbox" name="IsEnabled" lay-skin="switch" value="{{d.SystemName}}" lay-filter="enabled" lay-text="启用|停用" {{ d.IsEnabled ? 'checked' : ''}}>
    {{#  } }}
</script>
<script type="text/html" id="friendlyNameTpl">
    {{d.FriendlyName}}
    {{# if(d.ConfigurationUrl!=null){}}
     <a class="layui-btn layui-btn-normal layui-btn-xs layui-layout-right " style="margin-right:10px;" href="{{d.ConfigurationUrl}}"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    {{#}}}
</script>

<script>

    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table'], function () {
    var index = layer.load(2, { shade: false });
        var table = layui.table
            , form = layui.form;
        //分类管理
        table.render({
            elem: '#LAY-topic-list'
            , url: '@Html.Raw(Url.Action("ListSelect", "Plugin"))' //模拟接口
            ,method:'post'
            , page: true //开启分页
            , even: true
            , limit: 15
            , limits: [15,30,50,100]
            , cols: [[
                { type: 'numbers', fixed: 'left' }
                , { field: 'Group', title: '群组', width: 180 }
                , { field: 'FriendlyName', title: '名称', minWidth: 150, templet: '#friendlyNameTpl' }
                , { field: 'IsEnabled', title: '启用', width: 100, templet: '#isEnabledTpl' }
                , { field: 'Installed', title: '是否安装', templet: '#publishedTpl', width: 180, align: 'center' }
            ]]
            , text: { none: '一条数据也没有^_^' }
            , done: function () {
                layer.close(index);
            }
        });

        //监听锁定操作
         form.on('switch(published)', function (obj) {
             var check = obj.elem.checked;
             if (check) {
                 $.post('@Url.Action("Install")', { SystemName: this.value });
             } else {
                 $.post('@Url.Action("Uninstall")', { SystemName: this.value });
             }
        })

        form.on('switch(enabled)', function (obj) {
            var check = obj.elem.checked;
            $.post('@Url.Action("IsEnabled")', { SystemName: this.value,IsEnabled:check });
        })

        //监听工具条
        table.on('tool(LAY-topic-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除？', function (index) {
                    obj.del();
                    $.post('@Url.Action("Delete")', { id: obj.data.Id });
                    layer.close(index);
                });

            }
        });
        var $ = layui.$, active = {}
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>

